home *** CD-ROM | disk | FTP | other *** search
- Path: HOPPER.ACM.ORG!news
- From: varnk@e62.diebold.com (Ken Varn)
- Newsgroups: comp.lang.c++
- Subject: Need help with strstream
- Date: 1 Apr 1996 13:39:05 GMT
- Organization: Diebold
- Message-ID: <4jom9q$an4@HOPPER.ACM.ORG>
- NNTP-Posting-Host: 199.218.232.47
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- Let me start out by saying that I am really new to C++. I am trying to
- use an object created from the strstream class in a template class that I am
- creating.
-
- i.e.
-
- template <class DataType> LinkItem {
- private:
- HWND Window;
- DataType Data;
-
- public:
- strstream Stream;
-
- ....
- ....
-
- }
-
- I have member functions that will be used to transfer the Data to the Window
- and vice versa as well as various other member functions for getting,
- setting, etc.. The Window takes Text data only. So I am using the strstram
- class to allow me to convert the text data to DataType data and vice versa.
- I want the strstream object to be a public data member so that users of this
- class can change the format of numeric values when they are transfered to
- text format.
-
- The documentation I have on strstream is a bit vague.
- I want the Stream object to create its processing buffer using dynamic
- allocation. I read that this will occur if it is not supplied with a buffer
- at construction time. How do I reset the strstream object to dynamically
- allocate a new transfer beffer each time it is used? How do I get the length
- of the text that is stored in the buffer? I am real worried about causing a
- memory leak here, so I want to make sure that I do this right.
-
- I am calling it in a member function like this:
-
- void Transfer()
-
- {
- char *Text;
- int Length;
-
- // Need to reset Stream buffer here.
- Stream << Data;
-
- // Need length of buffer here
- Text = new char[Length];
-
- Stream >> Text;
-
- // Store text to window
- ...
- ...
-
- delete Text[];
- }
-
-